package com.yc.sp_index;

import com.yc.sp_index.web.VideoPlayerAction;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@ComponentScan("com.yc.sp_index")
@ConditionalOnProperty(prefix = "myconfig.upload",name = "enable")
@EnableWebMvc
public class BeanConfig implements WebMvcConfigurer {
    //配置静态资源映射
    @Resource
    private VideoPlayerAction videoPlayerAction;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //如果配置了静态资源，官方原有的静态资源映射目录（static）会被替代
        registry.addResourceHandler("/**")// /**  表示N级目录
                .addResourceLocations("classpath:static/");
        registry.addResourceHandler(videoPlayerAction.getWebpath()+"/**")
                .addResourceLocations("file:/"+videoPlayerAction.getUploadDir()+"/");
    }
}
